package com.quectel.emp.controller.fromcms;

import com.quectel.constant.sys.SysConfigKeyConstants;
import com.quectel.emp.util.SessionHolder;
import com.quectel.sys.module.sys.service.SysConfigService;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import com.quectel.util.security.RandomHeaderSignUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * cms的传递
 *
 * @author: cl
 * @email: louis.cao@quectel.com
 * @date: 2022-06-08 10:27:00
 */
@RestController
@RequestMapping("cms/command")
@Tag(name = "CommandController", description = "命令相关api")
public class CommandController {
    @DubboReference
    private SysConfigService sysConfigService;

    @PostMapping("disableDeptUser")
    public Response<Object> disableDeptUser(@RequestBody Long[] ids, HttpServletRequest request) {
        boolean checkSuccess =
                RandomHeaderSignUtils.checkSign(Request.parseHeaders(request), sysConfigService.getConfigValueByKey(SysConfigKeyConstants.COMMON_SALT));
        if (checkSuccess) {
            for (Long id : ids) {
                SessionHolder.removeUserToken(id);
            }
        }
        return Response.ok();
    }
}
